JavaScript String numToString() Converting a number to a string function numToString(number) {!^CR^!!^LF^! !^TAB^! number = ""!^CR^!!^LF^! !^TAB^! return number!^CR^!!^LF^! }!^CR^!!^LF^!
JavaScript String stringReplace() Replacing a substring within a string (Netscape 2.0) function stringReplace(originalString, findText, replaceText) { !^CR^!!^LF^! !^TAB^! var pos = 0 !^CR^!!^LF^! !^TAB^! var len = findText.length !^CR^!!^LF^! !^TAB^! pos = originalString.indexOf(findText) !^CR^!!^LF^! !^TAB^! while (pos != -1) { !^CR^!!^LF^! !^TAB^! preString = originalString.substring(0, pos) !^CR^!!^LF^! { !^TAB^! postString = originalString.substring(poslen, originalString.length) !^CR^!!^LF^! !^TAB^! originalString = preString replaceText postString !^CR^!!^LF^! !^TAB^! pos = originalString.indexOf(findText) !^CR^!!^LF^! !^TAB^! } !^CR^!!^LF^! !^TAB^! return originalString !^CR^!!^LF^! } !^CR^!!^LF^!
JavaScript Window showWindow() Opening a new small window function showWindow() { !^CR^!!^LF^!!^TAB^!objWindow = window.open("", "", "width=600,height=300") !^CR^!!^LF^!!^TAB^!objWindow.document.write("")!^CR^!!^LF^!!^TAB^!objWindow.document.write("<p>")!^CR^!!^LF^!!^TAB^!objWindow.document.close()!^CR^!!^LF^!} !^CR^!!^LF^!
JavaScript Radio getRadioValue() Retrieving value from a group of radio buttons function getRadioValue(radioObject) { !^CR^!!^LF^!!^TAB^!var value = null !^CR^!!^LF^!!^TAB^!for (var i=0; i<radioObject.length; i++) { !^CR^!!^LF^!!^TAB^!if (radioObject[i].checked) { !^CR^!!^LF^!!^TAB^!!^TAB^!value = radioObject[i].value!^CR^!!^LF^!!^TAB^!!^TAB^!break } !^CR^!!^LF^!!^TAB^!} !^CR^!!^LF^!!^TAB^!return value !^CR^!!^LF^!} !^TAB^!!^CR^!!^LF^!
JavaScript Select getSelectValue() Retrieving value from a select object function getSelectValue(objectName) {!^CR^!!^LF^!!^TAB^!return objectName.options[objectName.selectedIndex].value!^CR^!!^LF^!}!^CR^!!^LF^!
JavaScript Select getSelectedItems() Retrieving list of values from a multiple selection list function getSelectedItems(selectObject) {!^CR^!!^LF^!!^TAB^!var list = "" !^CR^!!^LF^!!^TAB^!for (var i=0; i<objectName.length; i++) { !^CR^!!^LF^!!^TAB^!!^TAB^!if (objectName.options[i].selected) { !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!list += objectName.options[i].text + "<p>" !^CR^!!^LF^!!^TAB^!!^TAB^!} !^CR^!!^LF^!!^TAB^!} !^CR^!!^LF^!!^CR^!!^LF^!!^TAB^!return list !^CR^!!^LF^!} !^CR^!!^LF^!
JavaScript String String.prototype.replace Replacing a substring within a string String.prototype.replace = stringReplace!^CR^!!^LF^!!^TAB^!function stringReplace(findText, replaceText) { !^CR^!!^LF^! var len = findText.length!^CR^!!^LF^!!^TAB^!!^TAB^!var originalString = new String(this) !^CR^!!^LF^!!^TAB^!!^TAB^!var pos = 0 !^CR^!!^LF^!!^TAB^!!^TAB^!pos = originalString.indexOf(findText) !^CR^!!^LF^!!^TAB^!!^TAB^!while (pos != -1) { !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!preString = originalString.substring(0, pos)!^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!postString = originalString.substring(pos+len, originalString.length)!^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!originalString = preString + replaceText + postString!^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!pos = originalString.indexOf(findText) !^CR^!!^LF^!!^TAB^!!^TAB^!} !^CR^!!^LF^!!^TAB^!!^TAB^!return originalString!^TAB^!!^CR^!!^LF^!!^TAB^!} !^CR^!!^LF^!
JavaScript Text onFocus Select text when cursor enters field // Add to your field object definitions!^CR^!!^LF^!onFocus="this.select()"!^CR^!!^LF^!
JavaScript Browser <SCRIPT> Dynamic text based on browser Creating dynamic text based on type of browser <SCRIPT LANGUAGE = "JavaScript">!^CR^!!^LF^!<!--!^CR^!!^LF^!var browser = navigator.appName!^CR^!!^LF^!document.open()!^CR^!!^LF^!if (browser == "Netscape") { !^CR^!!^LF^!document.write("<h2>Welcome <a href='http://home.netscape.com'>Netscape</a> user.</h2><p><p>")} !^CR^!!^LF^!else { !^CR^!!^LF^!if (browser == "Microsoft Internet Explorer") { !^CR^!!^LF^!!^TAB^!!^TAB^!document.write("<h2>Welcome <a href='http://www.microsoft.com'>Microsoft</a>Internet Explorer user.</h2><p><p>") } !^CR^!!^LF^!!^TAB^!else { !^CR^!!^LF^!!^TAB^!!^TAB^!document.write("<h1>Welcome. But what browser are you using?</h1><p><p>") !^CR^!!^LF^!!^TAB^!} !^CR^!!^LF^!} !^CR^!!^LF^!document.write("We are glad you came to our Web site.<p><p>") !^CR^!!^LF^!document.write("Don't you wish you knew how we knew your browser type?") !^CR^!!^LF^!document.close()!^CR^!!^LF^!// -->!^CR^!!^LF^!</SCRIPT> !^CR^!!^LF^!
JavaScript Form <SCRIPT> Check for blank fields Check for blank fields on submittal <SCRIPT LANGUAGE="JavaScript">!^CR^!!^LF^!<!--!^CR^!!^LF^!!^TAB^!function checkFields() { !^CR^!!^LF^!!^TAB^!!^TAB^!var num = document.form1.elements.length!^CR^!!^LF^!!^TAB^!!^TAB^!var validFlag = true!^CR^!!^LF^!!^TAB^!!^TAB^!for (var i=0; i<num; i++) {!^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!if ((document.form1.elements[i].value == null !^CR^!!^CR^! !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^! document.form1.elements[i].value == "") && !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^! (typeof document.form1.elements[i] != 'submit' !^CR^!!^CR^! !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^! typeof document.form1.elements[i] != 'reset'))!^CR^!!^LF^! { !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!!^TAB^!validFlag = false !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!!^TAB^!alert("The " + document.form1.elements[i].name + !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!!^TAB^!!^TAB^!" field is blank. Please enter a value.") !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!!^TAB^!break } !^CR^!!^LF^!!^TAB^!!^TAB^!} !^CR^!
JavaScript Date Date.prototype.getFullYear Return full year Date.prototype.getFullYear = getFullYear!^CR^!!^LF^!function getFullYear() { !^CR^!!^LF^!var n = this.getYear()!^CR^!!^LF^!!^TAB^!n += 1900 !^CR^!!^LF^!!^TAB^!return n !^CR^!!^LF^!} !^CR^!!^LF^!
JavaScript Date Date.prototype.getActualMonth Return actual month Date.prototype.getActualMonth = getActualMonth!^CR^!!^LF^!function getActualMonth() { !^CR^!!^LF^!!^TAB^!var n = this.getMonth()!^CR^!!^LF^!!^TAB^!n += 1 !^CR^!!^LF^!!^TAB^!return n !^CR^!!^LF^!} !^CR^!!^LF^!
JavaScript Date Date.prototype.getActualDay Return actual day Date.prototype.getActualDay = getActualDay!^CR^!!^LF^!function getActualDay() { !^CR^!!^LF^!!^TAB^!var n = this.getDay()!^CR^!!^LF^!!^TAB^!n += 1 !^CR^!!^LF^!!^TAB^!return n !^CR^!!^LF^!} !^CR^!!^LF^!
LiveWire Request Check browser for JavaScript support Check browser for JavaScript support <SERVER> !^CR^!!^LF^!var browser = "" !^CR^!!^LF^!browser = request.agent!^CR^!!^LF^!if (browser.indexOf("Mozilla/") != -1) { !^CR^!!^LF^!ver = browser.substring(8,9) !^CR^!!^LF^!!^TAB^!verNum = parseInt(ver) !^CR^!!^LF^!!^TAB^!if (verNum >= 2) { !^CR^!!^LF^!!^TAB^!!^TAB^!redirect("http://url") !^CR^!!^LF^!!^TAB^!} !^CR^!!^LF^!} !^CR^!!^LF^!</SERVER> !^CR^!!^LF^!
LiveWire Request Show request properties in an HTML table Show request properties in an HTML table <html>!^CR^!!^LF^!<body>!^CR^!!^LF^!<h1>LiveWire Request Object Example</h1>!^CR^!!^LF^!<table width=80%>!^CR^!!^LF^!<tr><td width=50%>Browser Information!^TAB^!</td><td width=50%><server>write(request.agent);</server></td></tr>!^CR^!!^LF^!<tr><td width=50%>IP Address</td><td width=50%><server>write(request.ip);</server></td></tr>!^CR^!!^LF^!<tr><td width=50%>HTTP Method</td><td width=50%><server>write(request.method);</server></td></tr>!^CR^!!^LF^!<tr><td width=50%>HTTP Protocol</td><td width=50%><server>write(request.protocol);</server></td></tr>!^CR^!!^LF^!</table>!^CR^!!^LF^!</body>!^CR^!!^LF^!</html>!^CR^!!^LF^!
JavaScript Array createArray() Creating an Array (Netscape 2.0) function createArray(size) {!^CR^!!^LF^!!^TAB^!this.length = size!^CR^!!^LF^!!^TAB^!for (var i = 1; i <= size; i++) {!^CR^!!^LF^!!^TAB^!this[i] = null }!^CR^!!^LF^!!^TAB^!return this!^CR^!!^LF^!}!^CR^!!^LF^!
LiveWire Database setClientDbProperties Set Client Object Database Properties <!-- Start of setClientDbProperties -->!^CR^!!^LF^!<server>!^CR^!!^LF^! /*==========================================================================!^CR^!!^LF^! setClientDbProperties - Set Client Object Database Properties !^CR^!!^LF^!!^CR^!!^LF^! This frequent script sets four client object properties used !^CR^!!^LF^! for connecting to a database. !^CR^!!^LF^! !^CR^!!^LF^! NOTE: Place this code at the initialization of your application. You !^CR^!!^LF^! can then reference these properties throughout the application. !^CR^!!^LF^! !^CR^!!^LF^! Acadia Infuse Frequent Script!^CR^!!^LF^! =========================================================================*/!^CR^!!^LF^!!^CR^!!^LF^! client.type = "type";!^CR^!!^LF^! client.server = "server";!^CR^!!^LF^! client.id = "user";!^CR^!!^LF^! client.password = "password";!^CR^!!^LF^! client.database = "database";!^CR^!!^LF^!!^CR^!!^LF^!</server> !^CR^!!^LF^!<!-- End of setClientDbProperties -->!^CR^!!^LF^!
LiveWire Database serialDbConnect Serial database connection <!-- Start of serialDbConnect -->!^CR^!!^LF^!<server> !^CR^!!^LF^!!^CR^!!^LF^! /*==========================================================================!^CR^!!^LF^! serialDbConnect - Serial database connection !^CR^!!^LF^!!^CR^!!^LF^! This frequent script makes a serial connection to a database and allows !^CR^!!^LF^! you to define the action you wish to take on it. !^CR^!!^LF^! !^CR^!!^LF^! NOTE: Be sure client database properties are defined. If not, use !^CR^!!^LF^! clientDbProp (Client database properties) frequent script to do so. !^CR^!!^LF^!!^CR^!!^LF^! Acadia Infuse Frequent Script!^CR^!!^LF^! =========================================================================*/!^CR^!!^LF^!!^CR^!!^LF^! project.unlock(); !^TAB^!!^CR^!!^LF^!!^CR^!!^LF^! // Connect to database !^CR^!!^LF^! database.connect(client.type, !^CR^!!^LF^! client.server, !^CR^!!^LF^! client.id, !^CR^!!^LF^! client.password, !^CR^!!^LF^! client.database);!^CR^!!^LF^!!^CR^!!^LF^! if(!database.connected()) !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!!^CR^!!^LF^! write("Error: Unable to connect to database.")!^CR^!!^LF^!!^CR^!!^LF^! else {!^CR^!!^LF^!!^TAB^!!^TAB^!!^CR^!!^LF^! // *** Enter SQL database activity code here *** !^CR^!!^LF^!!^CR^!!^LF^! database.disconnect();!^CR^!!^LF^! } !^TAB^!!^TAB^!!^TAB^!!^TAB^!!^TAB^!!^CR^!!^LF^!!^CR^!!^LF^! project.unlock(); !^TAB^!!^CR^!!^LF^!!^CR^!!^LF^!</server>!^CR^!!^LF^!<!-- End of serialDbConnect -->
LiveWire Project createLastProjectId Create Last ProjectID <!-- Start of createLastProjectId -->!^CR^!!^LF^!<server> !^CR^!!^LF^!!^CR^!!^LF^! /*==========================================================================!^CR^!!^LF^! createLastProjectId - Create Last ProjectID!^CR^!!^LF^!!^CR^!!^LF^! This frequent script retrieves the highest user-defined ID value !^CR^!!^LF^! from a database and stores it in a project object property called !^CR^!!^LF^! 'LastID'. You can then work with this property to find the next !^CR^!!^LF^! available unique ID for your database (rather than accessing the !^CR^!!^LF^! database directly). !^CR^!!^LF^! !^CR^!!^LF^! NOTE: Assumes database connection is active.!^CR^!!^LF^! !^CR^!!^LF^! Acadia Infuse Frequent Script!^CR^!!^LF^! =========================================================================*/!^CR^!!^LF^!!^CR^!!^LF^! // *** Modify these variables *** !^CR^!!^LF^! var dbTable = "TableName"; !^CR^!!^LF^! var dbField = "FieldName"; !^CR^!!^LF^! !^CR^!!^LF^! if (!database.connected())!^CR^!!^LF^! !^CR^!!^LF^! write("Error: Unable to connect to database."); !^CR^!!^LF^! !^CR^!!^LF^! else {!^CR^!!^LF^! !^CR^!!^LF^! project.lock(); !^CR^!!^LF^! project.lastID = 0;!^CR^!!^LF^! !^CR^!!^LF^! cursor = database.cursor("select * from " + dbTable + " order by " + dbField);!^CR^!!^LF^! !^CR^!!^LF^! while(cursor.next()) { !^CR^!!^LF^!!^CR^!!^LF^! project.lastID = cursor.id; !^CR^!!^LF^! !^CR^!!^LF^! } !^CR^!!^LF^!!^CR^!!^LF^! cursor.close();!^CR^!!^LF^! project.unlock(); !^CR^!!^LF^! !^CR^!!^LF^! } !^CR^!!^LF^!!^CR^!!^LF^!</server>!^CR^!!^LF^!<!-- End of createLastProjectId -->
LiveWire Database insertDbRecord Insert record into a table <!-- Start of insertDbRecord -->!^CR^!!^LF^!<server> !^CR^!!^LF^!!^CR^!!^LF^! /*==========================================================================!^CR^!!^LF^! insertDbRecord - Insert record into a table !^CR^!!^LF^!!^CR^!!^LF^! This frequent script provides the framework for inserting a record !^CR^!!^LF^! into a table using a passthrough SQL statement. !^CR^!!^LF^! !^CR^!!^LF^! NOTE: Assumes database connection is active.!^CR^!!^LF^! !^CR^!!^LF^! Acadia Infuse Frequent Script!^CR^!!^LF^! =========================================================================*/!^CR^!!^LF^!!^CR^!!^LF^! // *** Modify this variable *** !^CR^!!^LF^! var dbTable = "TableName"; !^CR^!!^LF^! !^CR^!!^LF^! if (!database.connected())!^CR^!!^LF^! !^CR^!!^LF^! write("Error: Unable to connect to database."); !^CR^!!^LF^! !^CR^!!^LF^! else {!^CR^!!^LF^! !^CR^!!^LF^! project.lock(); !^CR^!!^LF^! !^CR^!!^LF^! database.execute("insert into" + dbTable + !^CR^!!^LF^! "(Field1, Field2, Field3)" + !^CR^!!^LF^! "values (Val1, Val2, Val3)"); !^CR^!!^LF^! !^CR^!!^LF^! project.unlock(); !^CR^!!^LF^! !^CR^!!^LF^! } !^CR^!!^LF^!!^CR^!!^LF^!</server>!^CR^!!^LF^!<!-- End of insertDbRecord -->
LiveWire Database deleteDbRecord Delete record from a table <!-- Start of deleteDbRecord -->!^CR^!!^LF^!<server> !^CR^!!^LF^!!^CR^!!^LF^! /*==========================================================================!^CR^!!^LF^! deleteDbRecord - Delete record from a table !^CR^!!^LF^!!^CR^!!^LF^! This frequent script deletes the record from the specified table !^CR^!!^LF^! which matches the ID passed in as a Request object property. A !^CR^!!^LF^! passthrough SQL statement is performed to delete the record. !^CR^!!^LF^! !^CR^!!^LF^! NOTE: Assumes database connection is active. Requires the Request !^CR^!!^LF^! property to be specified in order to perform successfully. !^CR^!!^LF^! !^CR^!!^LF^! Acadia Infuse Frequent Script!^CR^!!^LF^! =========================================================================*/!^CR^!!^LF^!!^CR^!!^LF^! // *** Modify these variables *** !^CR^!!^LF^! var dbTable = "TableName"; !^CR^!!^LF^! var dbField = "TableName.ID"; !^CR^!!^LF^! !^CR^!!^LF^! if (!database.connected())!^CR^!!^LF^! !^CR^!!^LF^! write("Error: Unable to connect to database."); !^CR^!!^LF^! !^CR^!!^LF^! else {!^CR^!!^LF^! !^CR^!!^LF^! project.lock(); !^CR^!!^LF^! !^CR^!!^LF^! if(request.ID != null) {!^CR^!!^LF^! !^CR^!!^LF^! database.execute("delete from " + dbTable + !^CR^!!^LF^! " where " + dbField + " = " + request.ID);!^CR^!!^LF^! !^CR^!!^LF^!!^TAB^!!^TAB^!!^TAB^!}!^CR^!!^LF^!!^CR^!!^LF^! project.unlock(); !^CR^!!^LF^!!^CR^!!^LF^! redirect("sendto.hmtl");!^CR^!!^LF^!!^CR^!!^LF^! } !^CR^!!^LF^!!^CR^!!^LF^!</server>!^CR^!!^LF^!<!-- End of deleteDbRecord -->
LiveWire Database fetchDbRecords Fetch records from a table <!-- Start of fetchDbRecords -->!^CR^!!^LF^!<server> !^CR^!!^LF^!!^CR^!!^LF^! /*==========================================================================!^CR^!!^LF^! fetchDbRecords - Fetch records from a table !^CR^!!^LF^!!^CR^!!^LF^! This frequent script provides the framework for performing a SELECT !^CR^!!^LF^! SQL query. !^CR^!!^LF^! !^CR^!!^LF^! NOTE: Assumes database connection is active.!^CR^!!^LF^! !^CR^!!^LF^! Acadia Infuse Frequent Script!^CR^!!^LF^! =========================================================================*/!^CR^!!^LF^!!^CR^!!^LF^! // *** Modify these variables *** !^CR^!!^LF^! var dbTable = "TableName"; !^CR^!!^LF^! var dbField = "FieldName"; !^CR^!!^LF^! var reqValue = "YourValue"; !^CR^!!^LF^! !^CR^!!^LF^! if (!database.connected())!^CR^!!^LF^! !^CR^!!^LF^! write("Error: Unable to connect to database."); !^CR^!!^LF^! !^CR^!!^LF^! else {!^CR^!!^LF^! !^CR^!!^LF^! project.lock(); !^CR^!!^LF^! !^CR^!!^LF^! cursor = database.cursor("select * from " + !^CR^!!^LF^! dbTable + " where " + !^CR^!!^LF^! dbField + "=" + reqValue);!^CR^!!^LF^! !^CR^!!^LF^! while(cursor.next()) { !^CR^!!^LF^!!^CR^!!^LF^! // *** Add code to work with result set *** !^CR^!!^LF^! !^CR^!!^LF^! } !^CR^!!^LF^!!^CR^!!^LF^! cursor.close();!^CR^!!^LF^! project.unlock(); !^CR^!!^LF^! !^CR^!!^LF^! } !^CR^!!^LF^!!^CR^!!^LF^!</server>!^CR^!!^LF^!<!-- End of fetchDbRecords -->!^CR^!!^LF^!
LiveWire Database showSQLTable Shows result set of a query in a SQLTable <!-- Start of showSQLTable -->!^CR^!!^LF^!<server> !^CR^!!^LF^!!^CR^!!^LF^! /*==========================================================================!^CR^!!^LF^! showSQLTable - Shows result set of a query in a SQLTable !^CR^!!^LF^!!^CR^!!^LF^! This frequent script provides the framework for performing a SELECT !^CR^!!^LF^! SQL query and displaying the result set in a LiveWire SQLTable. !^CR^!!^LF^! !^CR^!!^LF^! NOTE: Assumes database connection is active.!^CR^!!^LF^! !^CR^!!^LF^! Acadia Infuse Frequent Script!^CR^!!^LF^! =========================================================================*/!^CR^!!^LF^!!^CR^!!^LF^! // *** Modify these variables *** !^CR^!!^LF^! var dbTable = "TableName"; !^CR^!!^LF^! var dbField = "FieldName"; !^CR^!!^LF^! var reqValue = "YourValue"; !^CR^!!^LF^! !^CR^!!^LF^! if (!database.connected())!^CR^!!^LF^! !^CR^!!^LF^! write("Error: Unable to connect to database."); !^CR^!!^LF^! !^CR^!!^LF^! else {!^CR^!!^LF^! !^CR^!!^LF^! project.lock(); !^CR^!!^LF^! !^CR^!!^LF^! cursor = database.SQLTable("select * from " + !^CR^!!^LF^! dbTable + " where " + !^CR^!!^LF^! dbField + "=" + reqValue);!^CR^!!^LF^!!^CR^!!^LF^! cursor.close();!^CR^!!^LF^!!^CR^!!^LF^! project.unlock(); !^CR^!!^LF^! !^CR^!!^LF^! } !^CR^!!^LF^!!^CR^!!^LF^!</server>!^CR^!!^LF^!<!-- End of showSQLTable -->